var grid;
function initGrid(){
	grid = $("#maingrid").ligerGrid({
		url:WST.U('admin/renwu/pageQuery'),
		pageSize:WST.pageSize,
		pageSizeOptions:WST.pageSizeOptions,
		height:'99%',
        width:'100%',
        minColToggle:6,
        rownumbers:true,
        columns: [
            { display: 'id', name: 'id',isSort: false},
	        { display: '关键词', name: 'guanjianci',isSort: false},
	        { display: '图片', name: 'tupian',isSort: false,render: function (rowdata, rowindex, value){
				return "<a href='/"+rowdata['tupian']+"' target='_blank'><img src='/"+rowdata['tupian']+"' style='width:60px'></a>";
			}},
	        { display: '店铺名字', name: 'dianpu',isSort: false},
	        { display: '店铺链接', name: 'dianpulianjie',isSort: false},
	        { display: '宝贝链接', name: 'baobeilianjie',isSort: false},
			{ display: '宝贝链接', name: 'baobeilianjie',isSort: false},
			{ display: '放单时间', name: 'fangdanshijian2',isSort: false,render: function (rowdata, rowindex, value){
				return  rowdata['fangdanshijian2'];
			}},
			{ display: '间隔时间', name: 'jiangeshijian',isSort: false},
			{ display: '单量', name: 'danliang',isSort: false},
			{ display: '价格', name: 'danjia',isSort: false},
			{ display: '商家备注', name: 'shangjiabeizhu',isSort: false},
	        { display: '操作', name: 'op',isSort: false,render: function (rowdata, rowindex, value){
	            var h = "";
	            h += "<a href='javascript:toEdit(" + rowdata['id'] + ")'>修改</a> ";
	            h += "<a href='javascript:toDel(" + rowdata['id'] + ")'>删除</a> ";
	            return h;
	        }}
        ]
    });
}
function initStopGrid(){
	grid = $("#maingrid").ligerGrid({
		url:WST.U('admin/shops/pageStopQuery'),
		pageSize:WST.pageSize,
		pageSizeOptions:WST.pageSizeOptions,
		height:'99%',
        width:'100%',
        minColToggle:6,
        rownumbers:true,
        columns: [
            { display: '店铺编号', name: 'shopSn',isSort: false},
	        { display: '店铺名称', name: 'shopName',isSort: false},
	        { display: '店主姓名', name: 'shopkeeper',isSort: false},
	        { display: '店主联系电话', name: 'telephone',isSort: false},
	        { display: '店主店铺地址', name: 'shopAddress',isSort: false},
	        { display: '所属公司', name: 'shopCompany',isSort: false},
	        { display: '营业状态', name: 'shopAtive',isSort: false,render: function (rowdata, rowindex, value){
	        	return (rowdata['shopAtive']==1)?"营业中":"休息中";
	        }},
	        { display: '操作', name: 'op',isSort: false,render: function (rowdata, rowindex, value){
	            var h = "";
	            h += "<a href='javascript:toEdit(" + rowdata['shopId'] + ")'>修改</a> ";
	            h += "<a href='javascript:toDel(" + rowdata['shopId'] + ")'>删除</a> ";
	            return h;
	        }}
        ]
    });
}
function initEdit(opts){
    //时间插件
          WST.upload({
      pick:'#adFilePicker',
      formData: {dir:'users'},
      accept: {extensions: 'gif,jpg,jpeg,png',mimeTypes: 'image/jpg,image/jpeg,image/png,image/gif'},
      callback:function(f){
        var json = WST.toAdminJson(f);
        if(json.status==1){
        $('#uploadMsg').empty().hide();
        //将上传的图片路径赋给全局变量
        $('#tupian').val(json.savePath+json.thumb);
        $('#preview').html('<img src="'+WST.conf.ROOT+'/'+json.savePath+json.thumb+'"  height="152" />');
        }else{
          WST.msg(json.msg,{icon:2});
        }
    },
    progress:function(rate){
        $('#uploadMsg').show().html('已上传'+rate+"%");
    }
    });


}
function toEdit(id){
	location.href=WST.U('admin/Renwu/toEdit','id='+id);
}
function toDel(id){
	var box = WST.confirm({content:"您确定要删除该任务吗?",yes:function(){
	           var loading = WST.msg('正在提交数据，请稍后...', {icon: 16,time:60000});
	           $.post(WST.U('admin/Renwu/del'),{id:id},function(data,textStatus){
	           			  layer.close(loading);
	           			  var json = WST.toAdminJson(data);
	           			  if(json.status=='1'){
	           			    	WST.msg("操作成功",{icon:1});
	           			    	layer.close(box);
	           		            grid.reload();
	           			  }else{
	           			    	WST.msg(json.msg,{icon:2});
	           			  }
	           		});
	            }});
}
function checkLoginKey(obj){
	if($.trim(obj.value)=='')return;
	var params = {key:obj.value,userId:0};
	var loading = WST.msg('正在提交数据，请稍后...', {icon: 16,time:60000});
    $.post(WST.U('admin/users/checkLoginKey'),params,function(data,textStatus){
    	layer.close(loading);
    	var json = WST.toAdminJson(data);
    	if(json.status!='1'){
    		WST.msg(json.msg,{icon:2});
    		obj.value = '';
    	}
    });
}
function save(){
	$('#editFrom').isValid(function(v){
		if(v){
			var params = WST.getParams('.ipt');
			var loading = WST.msg('正在提交数据，请稍后...', {icon: 16,time:60000});
		    $.post(WST.U('admin/Renwu/'+((params.id==0)?"add":"edit")),params,function(data,textStatus){
		    	layer.close(loading);
		    	var json = WST.toAdminJson(data);
		    	if(json.status=='1'){
		    		WST.msg("操作成功",{icon:1});
		    		location.href=WST.U('admin/Renwu/index');
		    	}else{
		    		WST.msg(json.msg,{icon:2});
		    	}
		    });
		}
	});
}
function loadAuditGrid(){
	var params = WST.getParams('.j-ipt');
	grid.set('url',WST.U('admin/renwu/pageQuery',params));
}
function toExport(){
	var params = {};
	params = WST.getParams('.j-ipt');
	var box = WST.confirm({content:"您确定要导出订单吗?",yes:function(){
		layer.close(box);
		location.href=WST.U('admin/Renwu/toExport',params);
	}});
}

